import 'package:flutter/material.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/generated/assets.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/utils/utils_other.dart';
import 'package:flutter_09_game/widgets/button/debounce_gesture_detector.dart';
import 'package:flutter_09_game/widgets/image/auto_image.dart';
import 'package:flutter_09_game/widgets/image/image_view.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class WidgetUserHeader extends StatelessWidget {
  const WidgetUserHeader(
      {super.key,
      required this.userAvatar,
      required this.isOnline,
      required this.username,
      required this.memberCount,
      required this.userIdentity,
      required this.withdrawAddress,
      this.showWithdrawAddress = false});

  final String? userAvatar;
  final bool? isOnline;
  final String? username;
  final int? memberCount;
  final String? userIdentity;
  final String? withdrawAddress;
  final bool showWithdrawAddress;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 8.w),
      child: Row(
        children: [
          SizedBox(
            width: 44.w,
            height: 44.w,
            child: Stack(
              children: [
                Positioned.fill(
                    child: ImageView(
                  imageUrl: userAvatar,
                  radius: 22.w,
                  fit: BoxFit.cover,
                )),
                Positioned(
                  bottom: 0,
                  right: 0,
                  child: Container(
                    width: 16.w,
                    height: 16.w,
                    decoration: BoxDecoration(
                      color: isOnline == true
                          ? AppColor.homePrizePoolBgIndicator.withOpacity(0.12)
                          : AppColor.textPrimary.withOpacity(0.08),
                      shape: BoxShape.circle,
                    ),
                    child: Center(
                      child: Container(
                        width: 8.w,
                        height: 8.w,
                        decoration: BoxDecoration(
                          color: isOnline == true
                              ? AppColor.homePrizePoolIndicator
                              : AppColor.textPrimary.withOpacity(0.3),
                          shape: BoxShape.circle,
                        ),
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
          12.horizontalSpace,
          // 用户信息
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                // 用户名和直属人数
                Row(
                  children: [
                    Flexible(
                      child: Text(
                        username ?? '--',
                        style: TextStyle(
                          fontFamily: 'PingFang SC',
                          fontSize: 12.sp,
                          fontWeight: FontWeight.w500,
                          color: AppColor.textPrimary.withOpacity(0.94),
                        ),
                      ),
                    ),
                    8.horizontalSpace,
                    // 直属人数

                    AutoImage(
                      Assets.promotionCommissionUser,
                      width: 16.w,
                      height: 16.w,
                    ),
                    // 4.horizontalSpace,
                    Text(
                      '${(memberCount ?? 0) + 1}',
                      style: TextStyle(
                        fontFamily: 'PingFang SC',
                        fontSize: 14.sp,
                        fontWeight: FontWeight.w400,
                        color: AppColor.textPrimary.withOpacity(0.7),
                      ),
                    ),
                  ],
                ),
                4.verticalSpaceFromWidth,
                // 会员ID
                DebounceGestureDetector(
                    onTap: () => UtilsOther.copyMemberId(userIdentity ?? ''),
                    child: Row(
                      children: [
                        Flexible(
                          child: Text(
                            '${LocaleKeys.memberId.tr}：${userIdentity ?? '--'}',
                            style: TextStyle(
                              fontFamily: 'PingFang SC',
                              fontSize: 12.sp,
                              fontWeight: FontWeight.w400,
                              color: AppColor.textPrimary.withOpacity(0.7),
                            ),
                          ),
                        ),
                        4.horizontalSpace,
                        AutoImage(
                          Assets.promotionCommissionCopy,
                          width: 16.w,
                          height: 16.w,
                        ),
                      ],
                    )),
                Visibility(
                    visible: showWithdrawAddress == true,
                    child:
                        // 4.verticalSpaceFromWidth,
                        // 投注地址
                        Text(
                      '${LocaleKeys.betAddress.tr}：${UtilsOther.formatWithdrawAddress(withdrawAddress)}',
                      style: TextStyle(
                        fontFamily: 'PingFang SC',
                        fontSize: 12.sp,
                        fontWeight: FontWeight.w400,
                        color: AppColor.textPrimary.withOpacity(0.7),
                      ),
                    ).marginOnly(top: 4.w)),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
